#include "../../include/gui/UIElement.hpp"
#include "../../include/graphics/Transformation.hpp"
#include "../../include/graphics/gl/GLTexture.hpp"

using namespace klas;
using namespace gui;
using namespace graphics;
using namespace gl;

// Constructor
// ====================================
// Takes the filename of the texture 

UIElement::UIElement(string filename, math::Rectd& bounds, 
					 UIElement* parent, Behavior behave):	Sprite(new GLTexture(filename),
              Transformation(math::Vector2d(bounds.x, bounds.y))),
															m_bbox(bounds.x, bounds.y,
																	bounds.w, bounds.h)
														
{
	m_behavior = behave;
	m_UIParent = parent;

	m_position.x = bounds.x;
	m_position.y = bounds.y;

}

// RenderAt
// ================================
// Renders this UIElement at the 
// specified location. 
void UIElement::renderAt(math::Vector2d& pos)
{
	/*if(m_parent != NULL)
	{
    /* This would be bad pratice, because you lose all of the other transformations like scale, etc.  Use setPos. */
		/*setPos(pos + m_UIParent->m_position);
		setTransparency(m_parent->getTransparency()*m_transparency);
	}
	else
	{
		setPos(pos);
		setTransparency(m_transparency);
	}*/

	// Render each of the children.
	vector<UIElement*>::iterator iter = m_UIChildren.begin();
	for(iter; iter != m_UIChildren.end(); iter++)
	{
		((*iter)->renderAt(m_position + (*iter)->m_position));
	}

	// Render background.
	//render();
}


/*! Appear
	=====================================
	Causes the the UIElement to appear
	(or begin to appear) by the specified
	behavior. */

void UIElement::appear()
{
	//NOTE:	Only the default behavior is set up right now.
	//		I think I'll need a FSM to implement fade/risesrop
	//		behaviors.

	switch(m_behavior)
	{
		case none:
			m_transparency = 1.0;
	}

}

/*! Hide
	=========================
	yeah.
*/
void UIElement::hide()
{
	switch(m_behavior)
	{
		case none:
			m_transparency = 0.0;
	}
}